package com.showgood.socket {
	import flash.utils.ByteArray;
	/**
	 * ...
	 * @author bianpeng
	 */
	public class SocketCommandFactory {
		public function SocketCommandFactory() {
			
		}		
		public function unpack(byteArray:ByteArray):AbstractSocketCommand {
			var stamp:int = byteArray.readInt();
			var flag:int = byteArray.readShort();
			var command:AbstractSocketCommand = null;
			if ((flag & SocketConsts.FLAG_SINGLE_VO) != 0) {
				command = new SingleSocketCommand(0, stamp);
			}
			else if ((flag & SocketConsts.FLAG_ARRAY_VO) != 0) {
				command = new ArraySocketCommand(0, stamp);
			}
			command.unpack(byteArray);
			return command;
		}
		public function pack(command:AbstractSocketCommand, byteArray:ByteArray):void {
			command.pack(byteArray);
		}
		private static var _instance:SocketCommandFactory;
		public static function get instance():SocketCommandFactory {
			if (_instance == null) {
				_instance = new SocketCommandFactory();
			}
			return _instance;
		}
	}

}


